package com.stand.hardcode.controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.stand.hardcode.entity.StandUser;
import com.stand.hardcode.util.ApplicationProperties;
import com.stand.hardcode.util.RequestAttributes;

//logout
public class LogOutServlet extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		StandUser currentuser = (StandUser)req.getSession().getAttribute(RequestAttributes.CURRENT_USER);
		if(currentuser != null){
	
			UserService userService = UserServiceFactory.getUserService();
			req.getSession().invalidate();
			resp.sendRedirect(userService.createLogoutURL(ApplicationProperties.URL));
		}
		else{
		req.getSession().invalidate();
		resp.sendRedirect("/home");
		}
	}
	
}
